package com.codebattery.service;

import com.codebattery.domain.model.AccountInfo;
import com.codebattery.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountService {

    @Autowired
    private AccountRepository accountRepository;
    @Autowired
    private UserService userService;

    /**
     * 获取所有account信息
     *
     * @return
     *
     * @athor Eric
     * @date 2020-02-09
     */
    public Page<AccountInfo> listAll(Pageable pageable){

        //创建匹配器，组装查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式：模糊查询
                .withIgnoreCase(true) //改变默认大小写忽略方式：忽略大小写
                .withMatcher("dictName", ExampleMatcher.GenericPropertyMatchers.startsWith()) //采用“开始匹配”的方式查询
                .withMatcher("dictCode",ExampleMatcher.GenericPropertyMatchers.contains())
                //忽略属性：因为是int类型(基本类型有默认值)，需要忽略掉
                .withIgnorePaths("id","is_use_icon","orderNo",
                        "parentId","dictLevel","createUserId","dbStatus")
                .withIgnoreNullValues();

//        Example<AccountInfo> ex = Example.of(null, matcher);

        Page<AccountInfo> accountInfoList = accountRepository.queryAllAccountInfo(pageable);

        return accountInfoList;
    }

}
